//
//  XMLTabBarController.m
//  不得姐
//
//  Created by mac on 2017/9/2.
//  Copyright © 2017年 XML. All rights reserved.
//

#import "XMLTabBarController.h"
#import"XMLEssenceController.h"
#import"XMLfriendTrendController.h"
#import"XMLMeController.h"
#import"XMLNewController.h"
#import"XMLPublishController.h"
#import "UIImage+XMLRander.h"
#import "UITabBarItem+XMLFont.h"

@interface XMLTabBarController ()

@end

@implementation XMLTabBarController

-(void)viewDidLoad {
    [super viewDidLoad];
//    self.tabBar.tintColor = [UIColor blackColor];
    
    [self setUpChildViewControllers];
    [self setUpAllTabbarButtons];
    
}

//-(void)render{
//    UIImage *selImage = [UIImage imageNamed:@"tabBar_essence_click_icon"];
//    selImage =  [selImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    nav0.tabBarItem.selectedImage = selImage;
//}

//-(void)setTabbarItemFont:(UIFont *)font item:(UITabBarItem *)item{
//    
//    NSMutableDictionary *attribute = [NSMutableDictionary dictionary];
//
//    attribute[NSFontAttributeName] = font;
//    [item setTitleTextAttributes:attribute forState:UIControlStateNormal];
//    
//}


//程序一启动就加载
+(void)load{
    
//    //修改字体
//    UITabBarItem *item = [UITabBarItem appearance];
//    NSMutableDictionary *attribute = [NSMutableDictionary dictionary];
//    attribute[NSFontAttributeName] = [UIFont systemFontOfSize:13];
//    [item setTitleTextAttributes:attribute forState:UIControlStateNormal];
    
}

//本类或者子类第一次调用，有可能被多次调用
+(void)initialize{
//    
//    if(self == [XMLTabBarController class]){
//        
//        //修改字体
//        UITabBarItem *item = [UITabBarItem appearance];
//        NSMutableDictionary *attribute = [NSMutableDictionary dictionary];
//        attribute[NSFontAttributeName] = [UIFont systemFontOfSize:13];
//        [item setTitleTextAttributes:attribute forState:UIControlStateNormal];
//   
//    }
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
       //修改字体
        UITabBarItem *item = [UITabBarItem appearance];
        NSMutableDictionary *attribute = [NSMutableDictionary dictionary];
        attribute[NSFontAttributeName] = [UIFont systemFontOfSize:13];
        [item setTitleTextAttributes:attribute forState:UIControlStateNormal];
    });
    
    
}

//设置所有按钮
-(void)setUpAllTabbarButtons{
   //0
    UINavigationController *nav0 = self.childViewControllers[0];
     nav0.tabBarItem.title = @"精华";
    nav0.tabBarItem.image = [UIImage imageNamed:@"tabBar_essence_icon"];
    nav0.tabBarItem.selectedImage = [UIImage randerOriginalImageNamed:@"tabBar_essence_click_icon"];
   //修改字体
//    [nav0.tabBarItem setFont:[UIFont systemFontOfSize:13]];
//    UITabBarItem *item = [UITabBarItem appearance];
//    NSMutableDictionary *attribute = [NSMutableDictionary dictionary];
//    attribute[NSFontAttributeName] = [UIFont systemFontOfSize:13];
//    [item setTitleTextAttributes:attribute forState:UIControlStateNormal];
    
   
    
    //1
    UINavigationController *nav1 = self.childViewControllers[1];
    nav1.tabBarItem.title = @"新帖";
    nav1.tabBarItem.image = [UIImage imageNamed:@"tabBar_new_icon"];
    nav1.tabBarItem.selectedImage = [UIImage randerOriginalImageNamed:@"tabBar_new_click_icon"];
//    //修改字体
//    [nav1.tabBarItem setFont:[UIFont systemFontOfSize:13]];
    
    
    //2
    UIViewController *vc2 = self.childViewControllers[2];
//     nav2.tabBarItem.title = @"发布";
    vc2.tabBarItem.image = [UIImage imageNamed:@"tabBar_publish_icon"];
    vc2.tabBarItem.selectedImage = [UIImage randerOriginalImageNamed:@"tabBar_publish_click_icon"];
//  //修改字体
//    [vc2.tabBarItem setFont:[UIFont systemFontOfSize:13]];
    
    //3
    UINavigationController *nav3 = self.childViewControllers[3];
     nav3.tabBarItem.title = @"关注";
    nav3.tabBarItem.image = [UIImage imageNamed:@"tabBar_friendTrends_icon"];
    nav3.tabBarItem.selectedImage = [UIImage randerOriginalImageNamed:@"tabBar_friendTrends_click_icon"];
//    //修改字体
//    [nav3.tabBarItem setFont:[UIFont systemFontOfSize:13]];
    
    //4
    UINavigationController *nav4 = self.childViewControllers[4];
     nav4.tabBarItem.title = @"我的";
    nav4.tabBarItem.image = [UIImage imageNamed:@"tabBar_me_icon"];
    nav4.tabBarItem.selectedImage = [UIImage randerOriginalImageNamed:@"tabBar_me_click_icon"];
//    //修改字体
//    [nav4.tabBarItem setFont:[UIFont systemFontOfSize:13]];
    
  
    
}

-(void)setUpChildViewControllers{
    
    XMLEssenceController * vc0 = [[XMLEssenceController alloc] init];
    vc0.view.backgroundColor = [UIColor blueColor];
    UINavigationController * nav0 = [[UINavigationController alloc]initWithRootViewController:vc0];
    
    XMLNewController * vc1 = [[XMLNewController alloc] init];
    vc1.view.backgroundColor = [UIColor redColor];
    UINavigationController * nav1 = [[UINavigationController alloc]initWithRootViewController:vc1];
    
    XMLPublishController * vc2 = [[XMLPublishController alloc] init];
    vc2.view.backgroundColor = [UIColor greenColor];
    
    
    XMLfriendTrendController * vc3 = [[XMLfriendTrendController alloc] init];
    vc3.view.backgroundColor = [UIColor yellowColor];
    UINavigationController * nav3 = [[UINavigationController alloc]initWithRootViewController:vc3];
    
    XMLMeController * vc4 = [[XMLMeController alloc] init];
    vc4.view.backgroundColor = [UIColor whiteColor];
    UINavigationController * nav4 = [[UINavigationController alloc]initWithRootViewController:vc4];
    
    [self addChildViewController:nav0];
    [self addChildViewController:nav1];
    [self addChildViewController:vc2];
    [self addChildViewController:nav3];
    [self addChildViewController:nav4];
    

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
